function [backupPathTable] = calculateBackupPath1(primaryPath, primaryPathTable, backupPathTable1, disp_loc, matrix)
  PR = length(primaryPath);
  BP1 = length(backupPathTable1);
  pr = length(primaryPathTable);  
  sender = primaryPathTable(1,1);
  backupPathTable = zeros(1,1);
  nodesAreUsed = zeros(1,1);
  numberOfBackupPathNodes = 1;
  backupPathTable(numberOfBackupPathNodes) = sender;
  middleNode = 0;
  dist1 = -1;
  for i = 2:pr
       receiver = primaryPathTable(i); 
       [neighborsS] = node_neighbors(sender,matrix);%This function will return the neighbors for certain node.
       [neighborsR] = node_neighbors(receiver,matrix);
       S = length(neighborsS);
       R = length(neighborsR);  
       middleNodeArray = zeros(1,1);
       DBNR = zeros(1,1);
       
       counter = 1;
       changeNode = 1;
       for j = 1 : S
               sndNeigh = neighborsS(j);
               [xR,yR]=find_Coordinates(receiver, disp_loc);

               for q = 1 : R           
                  rcvNeigh = neighborsR(q);
                  if sndNeigh == rcvNeigh
                      LB = length(backupPathTable);
                      %#######################This loop for make each node protect only one link#############                
                      for d = 1: LB
                         if sndNeigh == backupPathTable(d)
                             changeNode = -1;
                         end
                      end
                      if changeNode == 1
                          [xN,yN]=find_Coordinates(sndNeigh, disp_loc);
                          dist2 = distance(xN,yN,xR,yR);                      
                          if dist1 < dist2
                              middleNodeArray(counter) = sndNeigh;
                              DBNR(counter) = dist2;
                              counter = counter + 1;
                              middleNode = sndNeigh;
                              dist1 = dist2;
                          end  
                      end                      
                  end
                  changeNode = 1;
               end            
       end       
       if middleNode ~= 0
           sender = receiver;
           numberOfBackupPathNodes = numberOfBackupPathNodes +1;
           backupPathTable(numberOfBackupPathNodes) = middleNode;
           numberOfBackupPathNodes = numberOfBackupPathNodes +1;
           backupPathTable(numberOfBackupPathNodes) = sender;
       end
  end
    % Check all the nodes at the backup path that should no one use more than once.
    %[backupPathTable] = nodeUseOnce(primaryPathTable, backupPathTable, disp_loc,matrix);
    counter = 1;
    for i = 1:PR
        node = primaryPath(i);
        nodesAreUsed(counter) = node;
        counter = counter + 1;
    end
    for i = 1:BP1
        node = backupPathTable1(i);
        nodesAreUsed(counter) = node;
        counter = counter + 1;
    end
    UN = length(nodesAreUsed);
    nodesAreUsed1 = nodesAreUsed;
    for i = 1:UN
        node = nodesAreUsed1(i);
        testCounter = 0;
        UN1 = length(nodesAreUsed);
        loopOut = 1;
        j = 1;
        while j ~= UN1 && loopOut == 1
            j = j + 1; 
            node1 = nodesAreUsed(j);
            if node == node1
                testCounter = testCounter + 1;
                if testCounter > 1
                    nodesAreUsed(j) = [];
                    loopOut = 0;
                end 
            end
        end
    end
    
    [backupPathTable] = nodeUseOnce(nodesAreUsed, backupPathTable, disp_loc,matrix);        
    
    % Draw the backup path
    if dist1 ~= -1 
        k = length(backupPathTable);
            [x1,y1]=find_coordinates(backupPathTable(1), disp_loc);
            for i = 2:k
               [x2,y2]=find_coordinates(backupPathTable(i), disp_loc);
                line([x1 x2], [y1 y2], 'LineStyle',':', 'Color',[1,0,0]);
                x1=x2;
                y1=y2;
            end                            
    else
        disp('There is no backup path (This is a disconnected graph)');        
    end
end
